package com.houhanzhi.listener;

import com.houhanzhi.model.EventMessage;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 模拟rabbitMQ异常重试
 *
 * @author houhanzhi
 */
@Component
@Slf4j
@RabbitListener(queuesToDeclare = { @Queue("short_link.error.queue") })
public class ShortLinkErrorMQListener {

    /**
     * 处理器
     *
     * @param eventMessage 消息对象
     * @param message 常规对象
     * @param channel 信息通道
     * @throws IOException
     */
    @RabbitHandler
    public void shortLinkHandler(EventMessage eventMessage, Message message, Channel channel) throws IOException {
        log.error("告警：监听到消息ShortLinkErrorMQListener：eventMessage消息内容：{}", eventMessage);
        log.error("告警：Message消息内容：{}", message);
        log.error("告警成功，发送通知");
        // TODO 发送短信、邮件
    }
}
